package com.demo.cxf.server;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

//@Configuration
public class CxfConfiguration {

    private static final Logger logger = LoggerFactory.getLogger(CxfConfiguration.class);

    @Autowired
    private SpringBus springBus;

    @Bean
    public ServletRegistrationBean cxfServlet(){
        logger.info("初始化cxfServlet");
        return new ServletRegistrationBean(new CXFServlet(),"/webservice/*");
    }

    @Bean
    public IUserService userService(){
        logger.info("初始化userService");
        return new UserServiceImpl();
    }

    @Bean
    public Endpoint endpoint(){
        logger.info("初始化endPoint");
        EndpointImpl endpoint = new EndpointImpl(springBus, userService());
        endpoint.publish("/user");
        logger.info("初始化完成...");
        return endpoint;
    }
}
